"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deepToRaw = exports.createPrivateName = exports.wrapFuns = void 0;
var reactive_1 = require("./reactive");
var utils_1 = require("./utils");
/**
 * 生成一个执行所有方法的函数
 * @return {Function} 返回一个执行所有方法的函数
 */
function wrapFuns() {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return function () {
        var _this = this;
        var params = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            params[_i] = arguments[_i];
        }
        return args.map(function (fun) {
            try {
                fun && fun.apply(_this, params);
            }
            catch (e) {
                console.error(e);
                /** ignore */
            }
        });
    };
}
exports.wrapFuns = wrapFuns;
/**
 * 生成私有属性名
 * @return {String} 返回一个私有属性名
 */
exports.createPrivateName = function (name) { return "__" + name + "__"; };
/**
 * 值的获取（reactive/ref内容的获取）
 * @return {Object} 返回一个原生对象
 */
exports.deepToRaw = function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    return deepCopy((function (x) {
        if (utils_1.isFunction(x)) {
            return null;
        }
        if (reactive_1.isRef(x)) {
            return x.value;
        }
        if (utils_1.isArray(x)) {
            return x.map(function (item) { return exports.deepToRaw(item); });
        }
        if (utils_1.isPlainObject(x)) {
            var obj_1 = {};
            Object.keys(x).forEach(function (key) {
                obj_1[key] = exports.deepToRaw(x[key]);
            });
            return obj_1;
        }
        return x;
    }).apply(this, args));
};
/**
 * 深度拷贝
 * @return {Object} 返回一个原生对象
 */
function deepCopy(params) {
    var obj;
    if (typeof params === 'object') {
        if (Array.isArray(params)) {
            obj = [];
            for (var i = 0; i < params.length; i++) {
                obj.push(deepCopy(params[i]));
            }
        }
        else {
            obj = {};
            for (var c in params) {
                obj[c] = deepCopy(params[c]);
            }
        }
    }
    else {
        return params;
    }
    return obj;
}
